#include "src/utils/utils.h"
#include "src/matmul/matmul.h"

#define ROWS 1024
#define COLS 1024
// #define DTYPE float
// #define DTYPE half
#define DTYPE uint8_t
#define BL0CKSIZE 32



int main(){
    int rows = ROWS;
    int cols = COLS;
    int blocksize = BL0CKSIZE;
    using dtype = DTYPE;
    dtype* ha;
    dtype* hb;
    dtype* hc;
    dtype* hc_;
    dtype* da;
    dtype* db;
    dtype* dc;
    ha = (dtype*)malloc(rows*cols*sizeof(dtype));
    hb = (dtype*)malloc(rows*cols*sizeof(dtype));
    hc = (dtype*)malloc(rows*cols*sizeof(dtype));
    hc_ = (dtype*)malloc(rows*cols*sizeof(dtype));
    ptr_data_init(ha,rows*cols);
    ptr_data_init(hb,rows*cols);
    cudaMalloc((void**)&da,rows*cols*sizeof(dtype));
    cudaMalloc((void**)&db,rows*cols*sizeof(dtype));
    cudaMalloc((void**)&dc,rows*cols*sizeof(dtype));
    launch_cuda_matmul<dtype>(da,db,dc,rows,cols,blocksize,rows*cols);
    cudaMemcpy(hc,dc,rows*cols*sizeof(dtype),cudaMemcpyDeviceToHost);
    launch_cpu_matmul<dtype>(ha,hb,hc_,rows,cols);
    bool success  = check_cpu_cuda_cal_result<dtype>(hc,hc_,rows,cols);
    if(success){
        printf("%s CUDA && CPU get the same result!\n",typeid(dtype).name());
    }else{
        printf("%s CUDA && CPU get wrong result!\n",typeid(dtype).name());
    }
    free(ha);
    free(hb);
    free(hc);
    free(hc_);
    cudaFree(da);
    cudaFree(db);
    cudaFree(dc);
    return 0;
    
    
}